import uuid
from datetime import datetime
from sqlalchemy import Column, String, Text, DateTime, ForeignKey, Integer
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship

from app.core.database import Base


class MedicalRecord(Base):
    __tablename__ = 'medical_records'

    user_id = Column(UUID(as_uuid=True), ForeignKey('users.id'), nullable=False)
    file_id = Column(UUID(as_uuid=True), ForeignKey('uploaded_files.id'), nullable=False)
    disease_name = Column(String, nullable=True, comment="病症名称")
    report_category = Column(String, nullable=True, comment="报告分类")
    report_name = Column(String, nullable=True, comment="报告名称")
    report_date = Column(DateTime, nullable=True, comment="报告时间")
    hospital_name = Column(String, nullable=True, comment="就诊医院")
    extraction_status = Column(String, default="pending", comment="AI提取状态: pending, processing, completed, failed")
    upload_time = Column(DateTime, nullable=False, comment="上传时间，同一次上传的文件时间相同")

    # Relationships
    owner = relationship('User')
    file = relationship('UploadedFile', back_populates='medical_record')